<?php


namespace frontend\models\cyf;


use yii\db\ActiveRecord;

class Goods extends ActiveRecord
{

    public static function tableName()
    {

        return '2008a_goods';
    }

    public static function index($offset,$limit)
    {
        return self::find()
            ->select(['id','name','goods_no','market_price'])
            ->from('2008a_goods')
            ->offset($offset)
            ->limit($limit)
            ->asArray()->all();

    }

    /**
     * 轮播图
     * @return array|ActiveRecord[]
     * @name cyf
     */
    public static function getBanner()
    {
        return self::find()->select(['id','img'])->limit(3)->asArray()->all();
    }

    /**
     * 推荐类商品
     * @param $goods_id
     * @param $offset
     * @param $length
     * @return array|ActiveRecord[]
     * @cyf
     */
    public static function getGoodsByCommendId($goods_id,$offset,$length)
    {
        return self::find()->select(['id','name','goods_no','market_price','img'])
            ->where(['id'=>$goods_id])
            ->offset($offset)
            ->limit($length)
            ->asArray()
            ->all();
    }

    /**
     * 查询商品详情
     * @param $goods_id
     * @return array|ActiveRecord[]
     * @cyf
     */
    public static function goodsDetail($goods_id)
    {

        return self::find()
            ->where(['id'=>$goods_id])
            ->asArray()
            ->all()[0];
    }
}